package com.ffs.game.animation;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.ffs.game.scene.obj.ai.MonsterState;

import java.util.HashMap;
import java.util.Map;

/**
 * 动画管理
 *
 * @author ffs80
 */
public class AnimationManager {

    private static final AnimationManager INSTANCE = new AnimationManager();

    /**
     * 怪物动画
     */
    private final Map<MonsterState, Animation> monsterAnimation = new HashMap<>();

    /**
     * 玩家行走动画
     */
    private final Map<Integer, Animation> playerWalkAnimation = new HashMap<>();

    public static AnimationManager getInstance() {
        return INSTANCE;
    }

    /**
     * 初始化怪物动画
     */
    public void initMonsterAnimation() {
        Texture texture = new Texture(Gdx.files.internal("images/mr.png"));
        TextureRegion[][] regions = TextureRegion.split(texture, texture.getWidth() / 4, texture.getHeight() / 4);

        TextureRegion[] downRegions = new TextureRegion[]{regions[0][0], regions[0][1], regions[0][2], regions[0][3]};
        Animation downAnimation = new Animation(0.3f, downRegions);

        TextureRegion[] leftRegions = new TextureRegion[]{regions[1][0], regions[1][1], regions[1][2], regions[1][3]};
        Animation leftAnimation = new Animation(0.3f, leftRegions);

        TextureRegion[] rightRegions = new TextureRegion[]{regions[2][0], regions[2][1], regions[2][2], regions[2][3]};
        Animation rightAnimation = new Animation(0.3f, rightRegions);

        TextureRegion[] upRegions = new TextureRegion[]{regions[3][0], regions[3][1], regions[3][2], regions[3][3]};
        Animation upAnimation = new Animation(0.3f, upRegions);

        //巡逻动画
        monsterAnimation.put(MonsterState.active, downAnimation);
        //死亡动画
        monsterAnimation.put(MonsterState.die, leftAnimation);
        //出生动画
        monsterAnimation.put(MonsterState.born, rightAnimation);
        //战斗动画
        monsterAnimation.put(MonsterState.fight, upAnimation);
    }

    /**
     * 初始化玩家动画
     */
    public void initPlayerAnimation() {

    }

    /**
     * 获取动画
     */
    public Animation findAnimation(MonsterState state) {
        return monsterAnimation.get(state);
    }


}
